<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="/WEB-INF/page-base.tld" prefix="w" %>
<%
    String path = request.getContextPath();
%>
<style>
    .wicon {
        background-image: url(
        "");
        background-repeat: no-repeat;
        background-position: right center;
    }

    .required {
        color: red;
    }

    .Divspan {
        display: inline-block;
    }

    .Deno {
        height: 24px !important;
    }

    .limit {
        padding-left: 139px;
    }

    .clearance {
        line-height: 28px;
        height: 28px;
        background-color: #fff;
        margin-top: 7px;
    }

    .font50 {
        color: #505050 !important;
    }

    .mt0 {
        margin-top: 0px;
    }

    .pdleft {
        padding: 5px 0 5px 145px
    }

    .ding {
        padding: 5px 0;
    }

    #errormsg {
        position: fixed;
        width: 200px;
        height: 50px;
        line-height: 50px;
        padding: 1px 5px;
        text-align: center;
        background-color: #00A4F2;
        opacity: 0.5;
        color: #fff;
        left: 50%;
        margin-left: -50px;
        top: 50%;
        border-radius: 20px;
        z-index: 100000000;
    }
</style>
<form id="couponform" method="post">
    <w:hidden bind="bean.id"/>
    <w:hidden bind="bean.promotionid"/>
    <div class="headT">
        <span></span>
        <label>优惠劵定义</label>
    </div>
    <div id="errormsg" style="display: none;"></div>
    <div class="ui-formContent">
        <div>
            <label style="width:130px;text-align:right"><font class="required">*</font>推广平台：</label>
            <label class="radioButton">
                <input id="platform0" name="platform" checked="checked" class="radio-top mt0" type="radio" value="0"/>全平台
            </label>
            <label class="radioButton">
                <input id="platform1" name="platform" type="radio" class="radio-top mt0" value="1"/>PC端
            </label>
            <label class="radioButton">
                <input id="platform2" name="platform" type="radio" class="radio-top mt0" value="2"/>微商城
            </label>
        </div>
        <div>
            <label style="width:130px;text-align:right"><font class="required">*</font>优惠劵名称：</label>
            <input style="width:283px" name="couponname" value="<w:write bind="bean.name"/>"
                   styleClass="easyui-validatebox" autocomplete="off"/>
        </div>
        <div style="padding: 5px 0;">
            <label style="width:130px;text-align:right"><font class="required">*</font>有效期：</label>
            <div class="Divspan">
                <label class="radioButton">
                    <input id="immobilization" type="radio" name="fixed" class="radio-top mt0 validity" value="0"/>
                    <span class="font50">固定有效期：</span>
                    <input class="datainp wicon" id="fixedstarttime" name="fixedstarttime" type="text"
                           placeholder="请选择"
                           readonly> 到
                    <input class="datainp wicon" id="fixedendtime" name="fixedendtime"
                           type="text"
                           placeholder="请选择">
                </label>
            </div>
            <div class="pdleft" id="aa">
                <label class="radioButton">
                    <input id="movable" type="radio" name="fixed" class="radio-top mt0 validity" value="1"/>
                    <span class="font50">活动有效期：</span>
                    <input type="text" name="activeLife" id="activeLife"
                           oninput="this.value=this.value.replace(/\D/g,'')"
                           onafterpaste="this.value=this.value.replace(/\D/g,'')"> 天
                </label>
            </div>
        </div>
        <div>
            <label style="width:130px;text-align:right"><font class="required">*</font>优惠劵描述：</label>
            <input style="width:731px" name="couponDescribe" styleClass="easyui-validatebox"
                   value="<w:write bind="bean.explanation"/>"
                   autocomplete="off"/>
        </div>
        <div class="ding">
            <label style="width:130px;text-align:right"><font class="required">*</font>优惠劵面额：</label>
            <input type="text" list="url_list" name="couponDenomination" value="<w:write bind="bean.offer_money"/>"
                   oninput="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
            <datalist id="url_list">
                <option label="5" value="5"/>
                <option label="10" value="10"/>
                <option label="20" value="20"/>
                <option label="30" value="30"/>
                <option label="50" value="50"/>
                <option label="100" value="100"/>
            </datalist>
            <%--<select class="Deno" name="Deno" id="myse">--%>
            <%--<option>5</option>--%>
            <%--<option>10</option>--%>
            <%--<option>20</option>--%>
            <%--<option>30</option>--%>
            <%--<option>50</option>--%>
            <%--<option>100</option>--%>
            <%--<option>自定义</option>--%>
            <%--</select>--%>
            <%--<input type="text" name="coupDeno" class="coupDeno" style="display: none;" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">--%>
        </div>
    </div>
    <div class="headT">
        <span></span>
        <label>优惠劵限制</label>
    </div>
    <div class="ui-formContent">
        <div class="ding">
            <label style="width:130px;text-align:right">最小订单金额：</label>
            <input type="text" name="min_money" value="<w:write bind="bean.min_money"/>" onblur="moneyinput(this);"
                   autocomplete="off">
        </div>
        <div>
            <label style="width:130px;text-align:right">优惠劵总张数：</label>
            <input type="text" name="amount" value="<w:write bind="bean.amount"/>"
                   oninput="this.value=this.value.replace(/\D/g,'')"
                   onafterpaste="this.value=this.value.replace(/\D/g,'')">
        </div>
        <div class="clearance"></div>
        <div class="limit">
            <label>
                <input type="checkbox" id="convertible" name="convertible" class="convertible" value="0">
                <span>可兑换</span>
            </label>
            <div style="padding-left: 69px;">
                <label><font class="required">*</font>兑换时间：</label>
                <input class="datainp wicon" id="exchangestarttime" name="exchange_starttime" value="" type="text"
                       placeholder="请选择" disabled="disabled"
                > 到
                <input class="datainp wicon" id="exchangeendtime" name="exchange_endtime" value="" type="text"
                       placeholder="请选择" disabled="disabled">
            </div>
        </div>
        <div class="clearance"></div>
        <div class="limit">
            <label>
                <input type="checkbox" id="Receive" name="receive" class="Receive" value="0">
                <span>可领取</span>
            </label>
            <div style="padding-left: 69px;">
                <label><font class="required">*</font>领取时间：</label>
                <input class="datainp wicon" id="Receivestrttime" name="receive_starttime" value="" type="text"
                       placeholder="请选择" disabled="disabled"> 到
                <input class="datainp wicon" id="ReceiveEndtime" name="receive_endtime" value="" type="text"
                       placeholder="请选择" disabled="disabled">
            </div>
            <div style="padding-left: 47px;padding-top: 10px;">
                <label>单个客户限领：</label>
                <input type="text" name="limit_num" value="1" disabled="disabled" id="collar"
                       oninput="this.value=this.value.replace(/\D/g,'')"
                       onafterpaste="this.value=this.value.replace(/\D/g,'')"> 张
            </div>
        </div>
    </div>

    <div class="headT">
        <span></span>
        <label>参与方式</label>
    </div>
    <div class="ui-formContent">
        <p style="margin-left: 55px;">
            <input type="hidden" value="<w:write bind="bean.product_type"/>" name="product_type_val">
            <label class="radiocolor"><input name="bean4" id="qc" type="radio" class="inpradio" value="0">全场商品</label>
            <label class="radiocolor"><input name="bean4" id="bf" type="radio" class="inpradio" value="2">部分商品参加</label>
            <label class="radiocolor"><input name="bean4" id="zd" type="radio" class="inpradio" value="3">指定类目</label>
        </p>

        <p id="puctfl">
            <label title="商品分类" style="width:130px;text-align:right">商品分类：</label>
            <select id="classtree1" name="class_name" class="easyui-combotree" style="width:250px;height:28px;"
                    data-options="url:'<%=path %>/products/ProductClassPage@loadClassTree2.page',onLoadSuccess:loadclasstreeok"></select>
        </p>
    </div>
    </div>
    <div style="width: 100%;  text-align: center; position: absolute;z-index: 10000;bottom:0;"
         class="ui-buttonBar ui-btn">
        <input type="submit" value="完成"/>
    </div>
    <div class="easyui-panel ui-toolBar" border="false" id="selectpro" data-options="doSize:false">
        <table cellpadding="0" cellspacing="0" style="margin-top:5px">
            <tr>
                <td width="70" align="right">商品名称：</td>
                <td><w:text bind="bean.pname" style="width:120px;height:22px;"/></td>
                <td width="70" align="right">商品分类：</td>
                <td><select id="classtree" name="bean.classid" class="easyui-combotree"
                            style="width:250px;height:28px;"
                            data-options="url:'<%=path %>/products/ProductClassPage@loadClassTree2.page'"></select>
                </td>


                <td width="70" align="right">商品编码：</td>
                <td><w:text name="bean.code" bind="bean.code" style="width:300px;height:22px;"
                            onchange="value=(value.match(/\d+/g)||['']).join(',')"/></td>
                <td>
                    &nbsp;<a href="javascript:;" class="easyui-linkbutton" iconCls="icon_search"
                             onclick="query1()">查询</a>
                    &nbsp;<a href="javascript:;" class="easyui-linkbutton" iconCls="icon_search"
                             onclick="resetform()">重置</a>
                    &nbsp;<a href="javascript:;" class="easyui-linkbutton" iconCls="icon_search" onclick="addpro()"
                             id="see">查看已添加商品</a>
                </td>
            </tr>
        </table>
    </div>
</form>
<div title="部分商品" style="border: 1px solid #DDDDDD;">

    <script>
        window.productItems = {};
        window.productItemsTo = {};
        window.primarys = new Array();
    </script>


    <div style="border: 1px solid #DDDDDD;">
        <div id="chooseShowListPanel" class="easyui-panel" border="false" data-options="doSize:false,href:''">

        </div>
    </div>
</div>
<div style="width: 100%;height: 100px;"></div>

<script>
    var productItem = {};
    $(function () {
        var platform = '<w:write bind="bean.source"/>';
        $("#platform" + platform).prop("checked", true);

        var pro_class_value = $("[name='product_type_val']").val();
        if (pro_class_value === '0') {
            $("#chooseShowListPanel").hide();
            $("#qc").prop("checked", true);
        }

        if (pro_class_value == 3) {
            $("#chooseShowListPanel").hide();
            $("#zd").prop("checked", true);
        }

        if (pro_class_value == 1 || pro_class_value == 2) {
            $("#bf").prop("checked", true);
        }
        if (pro_class_value === "") {
            $("#bf").prop("checked", true);
        }
        showactivity();
        chooseShowList();
        selectedPro();
        $("input[name=bean4]").click(function () {
            showactivity();
        });

        var fixed = '<w:write bind="bean.activity_day"/>';
        if (fixed) {
            $("#movable").prop("checked", true);
            $("#activeLife").val(fixed);
        } else {
            $("#immobilization").prop("checked", true);
            $("[name='fixedstarttime']").val('<w:write bind="bean.startdate"/>');
            $("[name='fixedendtime']").val('<w:write bind="bean.enddate"/>');
        }

        var exchange = '<w:write bind="bean.exchange"/>';
        if (exchange) {
            $("#convertible").prop("checked", true);
            $("#convertible").val(1);
            $("#exchangestarttime").removeAttr("disabled");
            $("#exchangeendtime").removeAttr("disabled");
            $("#exchangestarttime").val('<w:write bind="bean.exchange_starttime"/>');
            $("#exchangeendtime").val('<w:write bind="bean.exchange_endtime"/>');
        }

        var receive = '<w:write bind="bean.receive"/>';
        if (receive) {
            $("#Receive").prop("checked", true);
            $("#Receive").val(1);
            $("#Receivestrttime").removeAttr("disabled");
            $("#ReceiveEndtime").removeAttr("disabled");
            $("#collar").removeAttr("disabled");
            $("#Receivestrttime").val('<w:write bind="bean.receive_starttime"/>');
            $("#ReceiveEndtime").val('<w:write bind="bean.receive_endtime"/>');
            $("#collar").val('<w:write bind="bean.limit_num"/>');
        }
    });
    //点击查看全部商品切换
    $.fn.toggle = function (fn) {
        var args = arguments,
            guid = fn.guid || jQuery.guid++,
            i = 0,
            toggler = function (event) {
                var lastToggle = ( jQuery._data(this, "lastToggle" + fn.guid) || 0 ) % i;
                jQuery._data(this, "lastToggle" + fn.guid, lastToggle + 1);
                event.preventDefault();
                return args[lastToggle].apply(this, arguments) || false;
            };
        toggler.guid = guid;
        while (i < args.length) {
            args[i++].guid = guid;
        }
        return this.click(toggler);
    }
    $("#see").toggle(
        function () {
            $("#seetab").hide();
            $("#see").css("background-color", " #C9C9C9");
            $("#seestab").show();
        },
        function () {
            $("#seetab").show();
            $("#see").removeAttr("style");
            $("#seestab").hide();
        }
    )
    function selectedPro() {
        productItem = {};
        <w:define id="selectedPro_id" bind="#selectedPro.id"/>
        <w:switch>
        <w:case bind="#selectedPro_id !=null">
        productItem.showlistid = "<w:write bind="#selectedPro.id"/>";
        productItem.showlistname = "<w:write bind="#selectedPro.name"/>";
        productItem.price = "<w:write bind="#selectedPro.price"/>";
        productItem.showlistcode = "<w:write bind="#selectedPro.code"/>";
        productItem.showlistB_chanjia = "<w:write bind="#selectedPro.B_chanjia"/>";
        productItem.showlistB_guige = "<w:write bind="#selectedPro.B_guige"/>";
        productItem.showlistclassname = "<w:write bind="#selectedPro.classname"/>";
        productItem.showlistproductamount = "<w:write bind="#selectedPro.productamount"/>";
        productItem.showlisttypes = "<w:write bind="#selectedPro.types"/>";
        </w:case>
        </w:switch>

        $("#pro").show();
    }
    <w:define bind="bean.product_val" id="classid"/>
    function loadclasstreeok() {
        $("#classtree1").combotree("setValue", "<%=classid%>");
    }
    //实现日期选择联动1
    var start = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            end.minDate = datas; //开始日选好后，重置结束日的最小日期
            endDates();
        },//选中日期回调
        okfun: function (elem, datas) {
            // alert(datas)
        }//点击确定回调
    };
    var end = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            start.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    //日期联动
    function endDates() {
        end.trigger = false; //结束日期的事件改成false
        $("#fixedendtime").jeDate(end);
    };
    $("#fixedstarttime").jeDate(start);
    $("#fixedendtime").jeDate(end);


    //实现日期选择联动2
    var startTwo = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            endTwo.minDate = datas; //开始日选好后，重置结束日的最小日期
            endDatesTwo();
        },//选中日期回调
        okfun: function (elem, datas) {
            // alert(datas)
        }//点击确定回调
    };
    var endTwo = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            startTwo.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    //日期联动
    function endDatesTwo() {
        endTwo.trigger = false; //结束日期的事件改成false
        $("#exchangeendtime").jeDate(endTwo);
    };
    $("#exchangestarttime").jeDate(startTwo);
    $("#exchangeendtime").jeDate(endTwo);


    //实现日期选择联动3
    var startThree = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            endThree.minDate = datas; //开始日选好后，重置结束日的最小日期
            endDatesThree();
        },//选中日期回调
        okfun: function (elem, datas) {
            // alert(datas)
        }//点击确定回调
    };
    var endThree = {
        format: 'YYYY-MM-DD hh:mm:ss',//日期格式
        minDate: $.nowDate({DD: 0}), //设定最小日期为当前日期
        maxDate: '2099-06-16 23:59:59', //最大日期
        festival: true,//是否显示节日
        isClaer: true,//是否显示清空
        isinitVal: false,//是否初始化时间
        zIndex: 300000,//层级高度
        choosefun: function (elem, datas) {
            startThree.maxDate = datas; //将结束日的初始值设定为开始日的最大日期
        }
    };
    //日期联动
    function endDatesThree() {
        endThree.trigger = false; //结束日期的事件改成false
        $("#ReceiveEndtime").jeDate(endThree);
    };
    $("#Receivestrttime").jeDate(startThree);
    $("#ReceiveEndtime").jeDate(endThree);

    /**
     *自定义validate验证：有效期
     **/
    $(function () {
        $.validator.addMethod("formradio", function (value, element) {//验证规则
                var tss = $('input:radio[name="fixed"]:checked').val();
                if (tss == 0 && $("#fixedstarttime").val() != '' && $("#fixedendtime").val() != '') {
                    return true;
                } else if (tss == 1 && $("#activeLife").val() != "") {
                    return true;
                }
                return false;
            }
        )
    });

    /**
     *自定义validate验证：可兑换
     **/

    $(function () {
        $.validator.addMethod("formconvertible", function (value, element) {//验证规则
                var src = $("input:checkbox[name='convertible']:checked").next().text();
                if ($("input[name='convertible']").is(':checked') == true) {
                    if (src != '' && $("#exchangestarttime").val() != '' && $("#exchangeendtime").val() != '') {
                        return true;
                    }
                } else {
                    return true;
                }
                return false;
            }
        )
    });

    /**
     *自定义validate验证：可领取
     **/

    $(function () {
        $.validator.addMethod("formReceive", function (value, element) {//验证规则
                var Receive = $("input:checkbox[name='Receive']:checked").next().text();
                if ($("input[name='Receive']").is(':checked') == true) {
                    if (Receive != '' && $("#Receivestrttime").val() != '' && $("#ReceiveEndtime").val() != '') {
                        return true;
                    }
                    return false;
                } else {
                    return true;
                }
                return false;
            }
        )
    });

    /*当前表单调用validate方法，实现表单验证功能*/
    $("#couponform").validate({
        debug: true, /*调试模式，验证通过也不跳转到目标页面*/
        rules: {
            /*配置验证规则*/
            platform: {
                required: true/*必填。如果验证方法不需要参数，则配置为true*/
            },
            platform: {
                required: true
            },
            couponname: {
                required: true
            },
            fixed: {
                required: true,
                formradio: $(".validity").val()
            },
            couponDescribe: {
                required: true
            },
            couponDenomination: {
                required: true
            },
            convertible: {
                formconvertible: $(".convertible").val()
            },
            Receive: {
                formReceive: $(".Receive").val()
            }

        },
        messages: {
            platform: {
                required: "推广平台不能为空，必选一项!"
            },
            couponname: {
                required: "优惠劵名称不能为空"
            },
            fixed: {
                formradio: "有效期格式有误"
            },
            couponDescribe: {
                required: "优惠劵描述不能为空"
            },
            couponDenomination: {
                required: "优惠劵面额不能为空"
            },
            convertible: {
                formconvertible: "可兑换时间格式有误"
            },
            Receive: {
                formReceive: "可领取时间格式有误"
            }
        },
        /* 重写错误显示消息方法,以吐司方式弹出错误消息 */
        /*获取所有必填项消息*/
        showErrors: function (errorMap, errorList) {
            var msg = "";
            $.each(errorList, function (i, v) {
                if (i == 0)//每次只弹出一个提示
                {
                    msg += (v.message + "\r\n");
                }
            });
            if (msg != "") {
                $("#errormsg").html(msg).fadeIn(300).delay(2000).fadeOut(300);
            }
        },
        /* 失去焦点时不验证 */
        onfocusout: false,
        submitHandler: function (form) {
            pedit_prodoctupdate();
        }
    });


    /**
     * 最小订单金额限制
     * @param obj
     */
    function moneyinput(obj) {
        obj.value = obj.value.trim().replace(/[^0-9|\.]/g, '');
        obj.value = obj.value.replace(/^\./, '0.');
        obj.value = obj.value.replace(/\.$/, '');
        if (obj.value.indexOf('.') > 0 && obj.value.indexOf('.') != (obj.value.length - 1)) {
            obj.value = obj.value.substring(0, obj.value.indexOf('.') + 1)
                + obj.value.substr(obj.value.indexOf('.') + 1, 2);
        }

        this.value = obj.value.replace(/\./g, '_').replace('_', '.').replace(/_/g, '');
    }

    /**
     * 优惠劵面额下拉框选中自定义选项触发事件
     */
    //        $("#myse").change(function () {
    //            if($(this).val()=="自定义"){
    //                $(".coupDeno").show();
    //            }else {
    //                $(".coupDeno").hide();
    //            }
    //        })

    /**
     * 可兑换勾选之后触发事件
     */
    $("#convertible").click(function () {
        if ($("#convertible").prop("checked")) {
            $("#convertible").val(1);
            $("#exchangestarttime").removeAttr("disabled");
            $("#exchangeendtime").removeAttr("disabled");
        } else {
            $("#convertible").val(0);
            $("#exchangestarttime").attr("disabled", "disabled");
            $("#exchangeendtime").attr("disabled", "disabled");
        }
    });

    /**
     * 可领取勾选之后触发的事件
     */
    $("#Receive").click(function () {
        if ($("#Receive").prop("checked")) {
            $("#Receive").val(1);
            $("#Receivestrttime").removeAttr("disabled");
            $("#ReceiveEndtime").removeAttr("disabled");
            $("#collar").removeAttr("disabled");
        } else {
            $("#Receive").val(0);
            $("#Receivestrttime").attr("disabled", "disabled");
            $("#ReceiveEndtime").attr("disabled", "disabled");
            $("#collar").attr("disabled", "disabled");
        }
    });

    /*参与方式单选框根据选中的值显示不同*/
    function showactivity() {
        switch ($("input[name=bean4]:checked").attr("id")) {
            case "qc":
                $("#puctfl").hide();
                $("#puctname").hide();
                $("#puctbar").hide();
                $("#puctbtn").hide();
                $("#seetab").hide();
                $("#selectpro").hide();
                $("#seestab").hide();
                break;
            case "bf":
                $("#puctfl").hide();
                $("#puctname").show();
                $("#puctbar").show();
                $("#puctbtn").show();
                $("#seetab").show();
                $("#selectpro").show();
                break;
            case "zd":
                $("#puctfl").show();
                $("#puctname").hide();
                $("#puctbar").hide();
                $("#puctbtn").hide();
                $("#seetab").hide();
                $("#selectpro").hide();
                $("#seestab").hide();
                break;
            default:
                break;
        }
    }

    function chooseShowList() {
        $w.execUrl(ctx + "/marketing/SinglePromotionPage@chooseProductList.page", {}, $('#chooseShowListPanel'));
    }

    function inp(obj) {
        //获取商品属性
        var productPromot = $(obj).parents("tr");
        productItem.showlistid = productPromot.find("input[name='showlistid']").val();
        productItem.showlistname = productPromot.find("input[name='showlistname']").val();
        productItem.price = productPromot.find("input[name='price']").val();
        productItem.showlistcode = productPromot.find("input[name='showlistcode']").val();
        productItem.showlistB_chanjia = productPromot.find("input[name='showlistB_chanjia']").val();
        productItem.showlistB_guige = productPromot.find("input[name='showlistB_guige']").val();
        productItem.showlistclassname = productPromot.find("input[name='showlistclassname']").val();
        productItem.showlistproductamount = productPromot.find("input[name='showlistproductamount']").val();
        productItem.showlisttypes = productPromot.find("input[name='showlisttypes']").val();
        $("#pro").show();
    }
    function addpro() {
        if (productItem["showlistcode"] == null) {
            $("#pro").hide();
        }
        if (productItem.showlistid) {
            $("#td1").text(productItem["showlistcode"]);
            $("#td2").text(productItem["showlistname"]);
            $("#td9").text(productItem["price"]);
            $("#td3").text(productItem["showlistB_chanjia"]);
            $("#td4").text(productItem["showlistB_guige"]);
            $("#td5").text(productItem["showlistclassname"]);
            $("#td6").text(productItem["showlistproductamount"]);
            $("#td7").text(productItem["showlisttypes"]);
            $("#td7").text(productItem["showlisttypes"]);
        }else {
            $("#prolist").toggleClass("classpro");

        }
    }

    function pedit_prodoctupdate() {
        pedit_saveProduct();
    }

    var pedit_saveing = false;
    function pedit_saveProduct() {
        if ($("input[name='bean4']:checked").val() == 3) {
            if ($("input[name='class_name']").val() == "" || $("input[name='class_name']").val() == "null") {
                $("#errormsg").html("请选择要添加的类目").show(300).delay(3000).hide(300);
                return false;
            }
        }

        if (!pedit_saveing) {
            if (!pedit_saveing) {
                pedit_saveing = true;//防止重复保存
                var data = productdata();
                if (!data) {
                    pedit_saveing = false;
                    return false;
                }
                $w.doUrl(ctx + "/couponSet/CouponSetPage@update.page", data, function (ret) {
                    $.messager.progress('close');
                    if (ret.state == 'ok') {
                        window.parent.$w.correctMsg("保存商品成功");
                        $w.closeCurrWin("ok");
                    } else if (ret.state == 'no') {
                        pedit_saveing = false;
                        window.parent.$w.alertMsg("编辑失败,商品已参加活动");
                    } else {
                        pedit_saveing = false;
                        window.parent.$w.alertMsg(ret.state);
                    }
                })
            }
        }
        //组合数据

        function productdata() {
            var data = {
                "bean.platform": $("input[name='platform']:checked").val(),
                "bean.couponname": $("[name='couponname']").val(),
                "bean.fixed": $("input[name='fixed']:checked").val(),
                "bean.fixedstarttime": $("[name='fixedstarttime']").val(),
                "bean.fixedendtime": $("[name='fixedendtime']").val(),
                "bean.activelife": $("[name='activeLife']").val(),
                "bean.couponDescribe": $("[name='couponDescribe']").val(),
                "bean.couponDenomination": $("[name='couponDenomination']").val(),
                "bean.min_money": $("[name='min_money']").val(),
                "bean.amount": $("[name='amount']").val(),
                "bean.convertible": $("[name='convertible']").val(),
                "bean.exchange_starttime": $("[name='exchange_starttime']").val(),
                "bean.exchange_endtime": $("[name='exchange_endtime']").val(),
                "bean.receive": $("[name='receive']").val(),
                "bean.receive_starttime": $("[name='receive_starttime']").val(),
                "bean.receive_endtime": $("[name='receive_endtime']").val(),
                "bean.limit_num": $("[name='limit_num']").val(),
                "bean.product_type": $("input[name='bean4']:checked").val(),
                "bean.classid": $("[name='class_name']").val(),
                "bean.id": $("[name='bean.id']").val(),
                "bean.promotionid": $("[name='bean.promotionid']").val(),
            };

            data["bean.product_val"] = productItem.showlistid;
            return data;
        }
    }
</script>
